home *** CD-ROM | disk | FTP | other *** search
- /*
-
- CDNR.c
- Superclass: CMacTCPDriver
-
- Dynamic name resolution implementation.
-
- Copyright © NCSA, University of Illinois; June 2, 1992
- Igor Livshits
-
- This code may be used, modified, and distributed free of charge and obligation.
-
- */
-
- #ifdef THINK_C
- #pragma options(!require_protos)
- #endif
-
- #include "CDNR.h"
-
-
- /*=====================*/
- // NOTE: The following code assumes only ONE instance of this object at any given time!
- /*===---------------===*/
-
- void CDNR::IDNR(char* fileName)
- Begin
- Handle theCode;
- CIsleResFile* theFile;
- SysEnvRec info; // System information
-
- resolver= Null;
- codeHandle= Null;
- fileMacTCP= Null;
-
- TRY
- {
- if (gSystem.systemVersion >= kSystem603)
- {
- SysEnvirons(kBasicVersion, &info);// Get system information
- theFile= new CIsleResFile; // We are only interested in the resource fork
- fileMacTCP= theFile;
- fileMacTCP->IResFile();
- fileMacTCP->FindCreatorType(info.sysVRefNum, kDefault, kMacTCP, kControlPanel, True);
- fileMacTCP->Open(fsRdPerm); // Open the driver
- } // Otherwise, it may be a Mac 512KE
-
- theCode= GetIndResource(kNameResolver, kNameResolverID);
- codeHandle= theCode;
- FailNILRes(codeHandle);
-
- DetachResource(codeHandle);
- FailResError();
- ForgetObject(fileMacTCP); // We are done with this file
-
- HLock(codeHandle); // Lock the DNR resource since it cannot be reloaded while opened
- FailMemError();
- resolver= (OSErrProcPtr) *codeHandle;
-
- FailOSErr( (*resolver)(kOpen, fileName) );
- }
- CATCH
- {
- ErrorAlert(gLastError, SpecifyMsg(kDNRError, kNoResolver));
-
- resolver= Null;
- ForgetObject(fileMacTCP);
- if (codeHandle)
- {
- HUnlock(codeHandle);
- ForgetHandle(codeHandle);
- }
- }
- ENDTRY;
- End
-
- /*===---------------===*/
-
- void CDNR::Dispose(void)
- Begin
- if (resolver)
- {
- FailOSErr( (*resolver)(kClose) ); // Close the name resolver
-
- HUnlock(codeHandle);
- FailMemError();
- ForgetHandle(codeHandle);
- resolver= Null;
- }
-
- inherited::Dispose();
- End
-
- /*===---------------===*/
-
- OSErr CDNR::StringToAddress(char* hostName, hostInfoPtr result, ProcPtr resultProcedure, char *done)
- Begin
- OSErr error;
-
- if (!resultProcedure) // Assign the default result procedure
- resultProcedure= (ProcPtr)ResultProc;
-
- if (resolver)
- {
- error= (*resolver)(kStringToAddress, hostName, result, resultProcedure, done);
- if (error == kCacheFault)
- {
- while (!(*done))
- ; // Wait for the domain name server to fetch the address
- error= noErr;
- }
- }
-
- return error;
- End
-
- /*===---------------===*/
-
- void CDNR::AddressToString(ip_addr address, char* addressStr)
- Begin
- if (resolver)
- FailOSErr( (*resolver)(kAddressToString, address, addressStr) );
- End
-
- /*===---------------===*/
-
- void CDNR::EnumerateCache(ProcPtr resultProcedure, char* done)
- Begin
- if (!resultProcedure) // Assign the default result procedure
- resultProcedure= (ProcPtr)EnumResultProc;
-
- if (resolver)
- FailOSErr( (*resolver)(kEnumerateCache, EnumResultProc, done) );
- End
-
- /*===---------------===*/
-
- OSErr CDNR::AddressToName(ip_addr address, hostInfoPtr result, ProcPtr resultProcedure, char *done)
- Begin
- OSErr error;
-
- if (!resultProcedure) // Assign the default result procedure
- resultProcedure= (ProcPtr)ResultProc;
-
- if (resolver)
- {
- error= (*resolver)(kAddressToName, address, result, resultProcedure, done);
- if (error == kCacheFault)
- {
- while (!(*done))
- ; // Wait for the domain name server to fetch the address
- error= noErr;
- }
- }
-
- return error;
- End
-
- /*=====================*/
- /*===---------------===*/
- /*=====================*/
-
- pascal void ResultProc(struct hostInfo* hInfoPtr, char* done)
- Begin
- #pragma unused (hInfoPtr)
-
- *done= True;
- End
-
- /*===---------------===*/
-
- pascal void EnumResultProc(struct cacheEntryRecord* cacheEntryPtr, char* done)
- Begin
- #pragma unused (cacheEntryPtr)
-
- *done= True;
- End
-
- /*===---------------===*/
- /*=====================*/